# Maintainer: Taozuhong <taozuhong@gmail.com>

_realname=libadwaita
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.3
pkgrel=1
pkgdesc="Building blocks for modern GNOME applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gnome.pages.gitlab.gnome.org/libadwaita/'
msys2_repository_url='https://gitlab.gnome.org/GNOME/libadwaita'
msys2_references=(
  'archlinux: libadwaita'
)
license=("spdx:LGPL-2.1-or-later")
depends=("${MINGW_PACKAGE_PREFIX}-appstream"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-graphene"
         "${MINGW_PACKAGE_PREFIX}-gtk4"
         "${MINGW_PACKAGE_PREFIX}-pango")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-vala"
             "${MINGW_PACKAGE_PREFIX}-sassc"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
source=("https://download.gnome.org/sources/libadwaita/${pkgver:0:3}/libadwaita-${pkgver}.tar.xz"
        0002-meson-fix-static-lib-install.patch)
sha256sums=('645f8659c975f75100d2c3b4f1e9ae0ebf13052d2b87015161b3972f60b46dfa'
            '2f5724a5ab3ac06334f0d72ea4bfe4f9a3aa6e2af6f17b602b78b75dd29f96f7')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/0002-meson-fix-static-lib-install.patch"
}

build() {
  local -a _static_flags=(
    -DGDK_STATIC_COMPILATION
    -DGIO_STATIC_COMPILATION
    -DGLIB_STATIC_COMPILATION
    -DGMODULE_STATIC_COMPILATION
    -DGOBJECT_STATIC_COMPILATION
  )

  CFLAGS+=" ${_static_flags[@]}" \
  CXXFLAGS+=" ${_static_flags[@]}" \
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    --default-library=static \
    --wrap-mode=nodownload \
    -Dexamples=true \
    -Ddocumentation=false \
    -Dintrospection=disabled \
    -Dtests=false \
    "build-${MSYSTEM}-static" \
    "${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    --default-library=shared \
    --wrap-mode=nodownload \
    -Dexamples=true \
    -Ddocumentation=false \
    -Dtests=false \
    "build-${MSYSTEM}-shared" \
    "${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-shared"
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install -C "${srcdir}/build-${MSYSTEM}-static" --destdir "${pkgdir}"
  ${MINGW_PREFIX}/bin/meson.exe install -C "${srcdir}/build-${MSYSTEM}-shared" --destdir "${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
